/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ece496.pkg496_spu;

/**
 *
 * @author Yiwen Su
 */
public class spu {
    public double spu (double[] sample, double threshold) {
        math_utils math_utils = new math_utils();
        double value = 0;
        double output = 0;
        
        value = math_utils.sample_filter(sample);
        
        if (value > 0.01 && value < threshold) {
            output = math_utils.round_1(dist_translate(value));
        } else {
            output = -1;
        }
        
        return output;
    }

    /*=================Translate readings into meters (START)=================*/
    public double dist_translate(double value) {
        double dist;
        math_utils math_utils = new math_utils();
        //calibration factors come from experimental results
        if (value <= 0.12) {
            dist = value / 0.11;
        } else {
            dist = value / 0.12;
        }
        
        return (math_utils.round_1(dist));
    }
    /*==================Translate readings into meters (END)==================*/
}